<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

$this->LoadHelper('OrderHelper');
$OrderHelper = new OrderHelper();

$this->LoadHelper('MemberHelper');
$MemberHelper = new MemberHelper();

$this->LoadHelper('BankHelper');
$BankHelper = new BankHelper();

$this->LoadHelper('MessageHelper');
$MessageHelper = new MessageHelper();

$check = $ApiHelper->tokenCheck($this->Param);
if(!$check['success']) ErrorMsg::ApiMsg($check['msg'], $check['code']);

switch ($this->Param['option']){
    case 'save': // 征信
        $params = $this->Param;
        //$ApiHelper->logSave('order_input_test', $this->Param);
        if($params['uid']){
            $member = $MemberHelper->getMember ($params['uid']);
            $params['o_uname'] = $member['u_realname'];
            $params['o_branch_type'] = $member['u_dp_type'];
            $params['o_branch_id'] = $member['u_dp_id'];
            $params['o_branch'] = $member['u_dpname'];
        }
        if($params['o_bank_id']){
            $bank_row = $BankHelper->bankRow($params['o_bank_id']);
            $params['o_bank'] = $bank_row['bk_name'];
        }
        $params['o_uid'] = $params['uid'];
        $result = $OrderHelper->orderSave($params);
        if($result['success']){
            $member_info = $MemberHelper->getMember($params['uid']);
            $r_msg = $OrderHelper->updateAttachoid($result['msg'],$params['temp_id']);
//            $MessageHelper->sendSingle(array(
//                'm_uid' => $params['uid'],
//                'm_title' => '征信录入成功',
//                'm_name' => $member_info['u_realname'],
//                'm_content' => '征信录入提交成功，等待征信查询通过',
//                'm_dateline' => NOW_TIME,
//                'm_oid' => $result['msg'],
//                'm_info' => serialize(array('status' => '征信提交', 'code' => $OrderHelper->statusChange('征信提交')))
//            ));
            $ApiHelper->logSave('order_input'. ($r_msg>100?'_'.$r_msg:''), $params);
            $model = $this->LoadModel('Public');
            $certs = $model->getList('order_cert', '*', array("`ct_oid` =?" =>$result['msg'], "`ct_status` = ?" => 'ok' ));
            if(!empty($certs)){
                foreach($certs as $k=>$v){
                    $certs[$k]['ct_fico_result'] = unserialize($v['ct_fico_result']);
                }
            }
//            \wodrow\tools\Tools::log($result);
//            \wodrow\tools\Tools::log($certs);
            ErrorMsg::ApiMsg('处理成功', 0, array(
                'o_id' => $result['msg'],
                'certs' => $certs,
            ));
        }else{
            ErrorMsg::ApiMsg($result['msg']);
        }
        break;
}